package com.explorer.ider.bootguide.fragment;

import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v4.app.Fragment;
import android.support.v7.widget.CardView;
import android.text.InputType;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.explorer.ider.bootguide.MainActivity;
import com.explorer.ider.bootguide.R;
import com.explorer.ider.bootguide.adapter.MyWifiListAdapter;
import com.explorer.ider.bootguide.utils.NetUtil;
import com.explorer.ider.bootguide.utils.WifiConnectUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Eric on 2016/9/5.
 */
public class FragmentNets extends Fragment{

    public static final String TAG = "FragmentNet";
    public static final String CONNECTIVITY_CHANGE_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
    public static final String CONNECTIVITY_CHANGE_ACTION_FAILURE = "android.net.conn.CONNECTIVITY_CHANGE_FILURE";
    public static final String CONNECTIVITY_CHANGE_ACTION_TIMEOUT = "android.net.conn.CONNECTIVITY_CHANGE_TIMEOUT";
    public static int whatNet = 0;//2 = wifi , 1 = ethernet;
    //public static boolean myPager = false;//该变量不设置时，初始化会自定跳过链接页

    //主页加载
    private View views;
    private TextView mGoneWifiButton;
    private TextView mGoneEthernetButton;
    private TextView wifiSSIDText;
    private LinearLayout mSelectNetLayout,mWifiConnectLayout,mEthernetConnectLayout;
    private CardView mNetSelectLockCradView;
    private Button mNetSelectSkipButton ,mNetBackPagerButton,mWifiRefreshButton,mNetSelectChangeButton;

    //wifi页加载
    private Button mWifiConnectButton , wifiPasswordVisbityBtn;
    private TextView mEthernetStatusTextView;
    private ListView mWifiSSIDEdit;
    private EditText mWifiPassWordEdit;
    private MyWifiListAdapter myWifiListAdapter;
    public String mSelectWifiSSID;
    public List<String> mWifiNameList;
    int[] mWifiWaftList;
    boolean[] mWifiIfPassWordList;
    ProgressDialog mProgressDialog;

    private CardView mWifiSelectLockCradView;

    //ethernet页加载
    private WifiManager mWifiManager = null;
    private Boolean connectStatus = false;
    private WifiConnectUtils mWifiConnectUtils;
    private List<ScanResult> mWifiHostList;
    private List<WifiInfo> mWifiInfoList;

    private ConnectivityManager mConnectivityManager;
    private Context context;
    private boolean isWifiPasswordVisbile;
    private LinearLayout wifiPasswordLayout;

    public static String CONNECTIVITY_CHANGE = "android.net.conn.CONNECTIVITY_CHANGE";
    public static String RSSI_CHANGE = "android.net.wifi.RSSI_CHANGED";
    public static String WIFI_STATE_CHANGE = WifiManager.WIFI_STATE_CHANGED_ACTION;

    
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(CONNECTIVITY_CHANGE);
        intentFilter.addAction(CONNECTIVITY_CHANGE_ACTION_TIMEOUT);
        intentFilter.addAction(CONNECTIVITY_CHANGE_ACTION_FAILURE);
        intentFilter.addAction(RSSI_CHANGE);
        intentFilter.addAction(WIFI_STATE_CHANGE);
        getActivity().registerReceiver(netWorkChangeReceiver,intentFilter);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }

    @Override
    public void onStart() {
        super.onStart();
//        IntentFilter intentFilter = new IntentFilter();
//        intentFilter.addAction(CONNECTIVITY_CHANGE_ACTION);
//        intentFilter.addAction(CONNECTIVITY_CHANGE_ACTION_TIMEOUT);
//        intentFilter.addAction(CONNECTIVITY_CHANGE_ACTION_FAILURE);
//        getActivity().registerReceiver(netWorkChangeReceiver,intentFilter);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        getActivity().unregisterReceiver(netWorkChangeReceiver);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        context = getActivity();
        if (views == null){
            views = inflater.inflate(R.layout.fragment_nets, container,false);
            initData();
            initView();
        }
        return views;
    }

    private void initData(){
        //wifi数据
        mWifiManager = (WifiManager) getActivity().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
        mWifiConnectUtils = new WifiConnectUtils(mWifiManager);
        mWifiHostList = mWifiConnectUtils.searchWifi();

        //以太网数据
        mConnectivityManager = (ConnectivityManager)getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
    }

    @TargetApi(Build.VERSION_CODES.M)
    private void initView() {
        //主页

//        final Animation mAnimationIn , mAnimationOut;
//        mAnimationIn = AnimationUtils.loadAnimation(getActivity(), R.anim.view_focus_animation_in);
//        mAnimationOut = AnimationUtils.loadAnimation(getActivity(),R.anim.view_focus_animation_out);
//        mAnimationIn.setFillAfter(true);
//        mAnimationOut.setFillAfter(true);
//        final Animation mAnimationIn1 , mAnimationOut1;
//        mAnimationIn1 = AnimationUtils.loadAnimation(getActivity(), R.anim.view_focus_animation_in);
//        mAnimationOut1 = AnimationUtils.loadAnimation(getActivity(),R.anim.view_focus_animation_out);
//        mAnimationIn1.setFillAfter(true);
//        mAnimationOut1.setFillAfter(true);
//        final Animation mAnimationIn2 , mAnimationOut2;
//        mAnimationIn2 = AnimationUtils.loadAnimation(getActivity(), R.anim.view_focus_animation_in);
//        mAnimationOut2 = AnimationUtils.loadAnimation(getActivity(),R.anim.view_focus_animation_out);
//        mAnimationIn2.setFillAfter(true);
//        mAnimationOut2.setFillAfter(true);

        wifiPasswordLayout = (LinearLayout)views.findViewById(R.id.wifi_connect_layout);
        wifiSSIDText = (TextView)views.findViewById(R.id.id_wifi_ssid_text);
        wifiPasswordVisbityBtn =(Button) views.findViewById(R.id.id_wifi_password_visbity_button);
        mGoneWifiButton = (TextView) views.findViewById(R.id.id_wifi_status_start_button);
        mGoneEthernetButton = (TextView) views.findViewById(R.id.id_ethernet_status_start_button);
        mSelectNetLayout = (LinearLayout) views.findViewById(R.id.id_net_select_layout);
        mEthernetConnectLayout = (LinearLayout) views.findViewById(R.id.id_ethernet_connect_layout);
        mNetSelectLockCradView = (CardView) views.findViewById(R.id.id_net_select_focus_lock_card_view);
        mNetSelectSkipButton = (Button) views.findViewById(R.id.id_net_select_skip_button);
        mNetBackPagerButton = (Button) views.findViewById(R.id.id_net_select_back_button);
        mNetSelectChangeButton = (Button) views.findViewById(R.id.id_net_select_change_button);
        mWifiRefreshButton = (Button) views.findViewById(R.id.id_net_select_refresh_button);
        MyNetSelectClickListener myNetSelectClickListener = new MyNetSelectClickListener();
        MyNetSelectFocusListener myNetSelectFocusListener = new MyNetSelectFocusListener();
        mGoneWifiButton.setOnClickListener(myNetSelectClickListener);
        mGoneWifiButton.setOnFocusChangeListener(myNetSelectFocusListener);

        mGoneEthernetButton.setOnClickListener(myNetSelectClickListener);
        mGoneEthernetButton.setOnFocusChangeListener(myNetSelectFocusListener);

        wifiPasswordVisbityBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (isWifiPasswordVisbile){
                    isWifiPasswordVisbile = false;
                    mWifiPassWordEdit.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD);
                    wifiPasswordVisbityBtn.setText(getResources().getString(R.string.show_password));
                }else {
                    isWifiPasswordVisbile = true;
                    wifiPasswordVisbityBtn.setText(getResources().getString(R.string.hide_password));
                    mWifiPassWordEdit.setInputType(InputType.TYPE_CLASS_TEXT);
                }
            }
        });

        mNetSelectSkipButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setAction(MainActivity.ACTION_TO_NEXT_PAGER3);
                getActivity().sendBroadcast(intent);
            }
        });
        mNetBackPagerButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setAction(MainActivity.ACTION_TO_BACK_PAGER2);
                getActivity().sendBroadcast(intent);
            }
        });
        mNetBackPagerButton.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
//                    v.startAnimation(mAnimationIn);
                    if (whatNet == 2){
                        mWifiSelectLockCradView.setVisibility(View.INVISIBLE);
                    }else {
                        mNetSelectLockCradView.setVisibility(View.INVISIBLE);
                    }
                }else if(!hasFocus){
//                    v.startAnimation(mAnimationOut);
                    if (whatNet == 2) {
                        mWifiSelectLockCradView.setVisibility(View.VISIBLE);
                    }else {
                        mNetSelectLockCradView.setVisibility(View.VISIBLE);
                    }
                }
            }
        });
        mNetSelectChangeButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (whatNet == 2 ){
                    ethernetVisibility();
                    mNetSelectChangeButton.setText(getString(R.string.string_go_to_wifi));
                }else if (whatNet == 1){
                    wifiVisibility();
                    mNetSelectChangeButton.setText(getString(R.string.string_go_to_ethernet));
                }
            }
        });
        mNetSelectChangeButton.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
//                    v.startAnimation(mAnimationIn);
                    if (whatNet == 2){
                        mWifiSelectLockCradView.setVisibility(View.INVISIBLE);
                    }else {
                        mNetSelectLockCradView.setVisibility(View.INVISIBLE);
                    }
                }else if (!hasFocus){
//                    v.startAnimation(mAnimationOut);
                    if (whatNet == 2) {
                        mWifiSelectLockCradView.setVisibility(View.VISIBLE);
                    }else {
                        mNetSelectLockCradView.setVisibility(View.VISIBLE);
                    }
                }
            }
        });
        mWifiRefreshButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getWifiInfo();
            }
        });
        mWifiRefreshButton.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
//                    v.startAnimation(mAnimationIn1);
                    if (whatNet == 2){
                        mWifiSelectLockCradView.setVisibility(View.INVISIBLE);
                    }else {
                        mNetSelectLockCradView.setVisibility(View.INVISIBLE);
                    }
                }else if(!hasFocus) {
//                    v.startAnimation(mAnimationOut1);
                    if (whatNet == 2) {
                        mWifiSelectLockCradView.setVisibility(View.VISIBLE);
                    }else {
                        mNetSelectLockCradView.setVisibility(View.VISIBLE);
                    }
                }
            }
        });

        mNetSelectSkipButton.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
//                    v.startAnimation(mAnimationIn2);
                    if (whatNet == 2){
                        mWifiSelectLockCradView.setVisibility(View.INVISIBLE);
                    }else {
                        mNetSelectLockCradView.setVisibility(View.INVISIBLE);
                    }
                }else if(!hasFocus){
//                    v.startAnimation(mAnimationOut2);
                    if (whatNet == 2) {
                        mWifiSelectLockCradView.setVisibility(View.VISIBLE);
                    }else {
                        mNetSelectLockCradView.setVisibility(View.VISIBLE);
                    }
                }
            }
        });



        //wifi页------------------------------------------------------------------------------------
        mWifiConnectLayout = (LinearLayout) views.findViewById(R.id.id_wifi_connect_layout);//-
        mWifiConnectButton = (Button) views.findViewById(R.id.id_wifi_connect_button);//-
        mWifiSSIDEdit = (ListView) views.findViewById(R.id.id_wifi_ssid_edit_list);
        mWifiPassWordEdit = (EditText) views.findViewById(R.id.id_wifi_password_edit_text);
        mWifiSelectLockCradView = (CardView) views.findViewById(R.id.id_wifi_focus_lock_card_view);
        getWifiInfo();
        MyWifiSelectOnItemClickListener mWifiClickListener = new MyWifiSelectOnItemClickListener();
        MyWifiSelectOnItemSelectListener mWifiSelectListener = new MyWifiSelectOnItemSelectListener();
        mWifiSSIDEdit.setAdapter(myWifiListAdapter);
        mWifiSSIDEdit.setOnItemClickListener(mWifiClickListener);
        mWifiSSIDEdit.setOnItemSelectedListener(mWifiSelectListener);
        mWifiConnectButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               final String passwordText = mWifiPassWordEdit.getText().toString();
                if (passwordText==null||passwordText.equals("")){
                    Toast.makeText(context,"請輸入密碼！",Toast.LENGTH_SHORT).show();
                    return;
                }
                if (passwordText.length()<8){
                    Toast.makeText(context,"密碼錯誤，請重新輸入！",Toast.LENGTH_SHORT).show();
                    return;
                }
                if (isEthernetConnect){
                    Toast.makeText(context,"請先斷開以太網！",Toast.LENGTH_LONG).show();
                    return;
                }

                showProgressDialog();
                new Thread(){
                    @Override
                    public void run() {
                        super.run();
                        boolean wifiStatus = mWifiConnectUtils.connect(mSelectWifiSSID,
                                passwordText,WifiConnectUtils.WifiCipherType.WIFICIPHER_WPA);

//                        if (wifiStatus){
//                            mHandler.sendEmptyMessage(1);
//                            Log.d("zhaoyf","wifiStatus = true");
//                        }else {
//                            mHandler.sendEmptyMessage(0);
//                            Log.d("zhaoyf","wifiStatus = false");
//                        }

                    }
                }.start();




                new Thread(){
                    @Override
                    public void run() {
                        super.run();
                        try {
                            sleep(10000);
                            Intent falseWifiBroadcast = new Intent();
                            falseWifiBroadcast.setAction(CONNECTIVITY_CHANGE_ACTION_FAILURE);
                            getActivity().sendBroadcast(falseWifiBroadcast);

//                            else {
//                                Intent falseWifiBroadcast = new Intent();
//                                falseWifiBroadcast.setAction(CONNECTIVITY_CHANGE_ACTION_TIMEOUT);
//                                getActivity().sendBroadcast(falseWifiBroadcast);
//                            }
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }.start();
            }
        });
        mWifiConnectButton.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
//                    v.startAnimation(mAnimationIn);
                }else {
//                    v.startAnimation(mAnimationOut);
                }
            }
        });
        mWifiPassWordEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
//                    v.startAnimation(mAnimationIn1);
                }else {
//                    v.startAnimation(mAnimationOut1);
                }
            }
        });



        //以太网页----------------------------------------------------------------------------------
        mEthernetStatusTextView = (TextView) views.findViewById(R.id.id_ethernet_status_text);
        if (NetUtil.isEthernetConnect(getActivity())){
//            toNext2();
            mEthernetStatusTextView.setText(getString(R.string.string_ethernet_connect_success));
            isEthernetConnect=true;
        }else{
            mEthernetStatusTextView.setText(getString(R.string.string_ethernet_connect_failure));
            isEthernetConnect=false;
        }
    }

    //主页逻辑
    class MyNetSelectClickListener implements View.OnClickListener {

        @RequiresApi(api = Build.VERSION_CODES.M)
        @Override
        public void onClick(View view) {
            mNetSelectChangeButton.setVisibility(View.VISIBLE);
            switch (view.getId()){
                case R.id.id_wifi_status_start_button:
                    if (mWifiConnectUtils.checkWifi())
                    wifiVisibility();
                    getWifiInfo();
                    mNetSelectChangeButton.setText(getString(R.string.string_go_to_ethernet));
                    break;
                case R.id.id_ethernet_status_start_button:
                    ethernetVisibility();
                    mNetSelectChangeButton.setText(getString(R.string.string_go_to_wifi));
                    break;
            }
        }
    }



    class MyNetSelectFocusListener implements View.OnFocusChangeListener{

        @Override
        public void onFocusChange(View view, boolean b) {
            switch (view.getId()){
                case R.id.id_wifi_status_start_button:
                    startNetSelectAnimation(view);
                    break;
                case R.id.id_ethernet_status_start_button:
                    startNetSelectAnimation(view);
                    break;
            }
        }
    }

    private void wifiConnect(String ssid,String pwd,int type){
        final boolean wifiStatus = mWifiConnectUtils.connect(mSelectWifiSSID,
                pwd,WifiConnectUtils.WifiCipherType.WIFICIPHER_WPA);


    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    private void getWifiInfo(){
        mWifiManager = (WifiManager) getActivity().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
        mWifiConnectUtils = new WifiConnectUtils(mWifiManager);
        mWifiHostList = mWifiConnectUtils.searchWifi();
        mWifiNameList = new ArrayList<String>();
        mWifiWaftList = mWifiConnectUtils.getWifiLevel();
        mWifiIfPassWordList = new boolean[mWifiHostList.size()];
        for (int i = 0; i < mWifiHostList.size(); i++) {
            mWifiNameList.add(mWifiHostList.get(i).SSID);
            mWifiIfPassWordList[i] = true;
        }
        if (myWifiListAdapter == null) {
            Log.i(TAG, "getWifiInfo: " +1);
            myWifiListAdapter = new MyWifiListAdapter(getActivity(), mWifiNameList, mWifiWaftList, mWifiIfPassWordList);
        }else {
            Log.i(TAG, "getWifiInfo: " +2);
            myWifiListAdapter = new MyWifiListAdapter(getActivity(), mWifiNameList, mWifiWaftList, mWifiIfPassWordList);
            Log.i(TAG, "getWifiInfo: " + mWifiNameList.size());
            mWifiSSIDEdit.setAdapter(myWifiListAdapter);
//            myWifiListAdapter.refreshWifiList( mWifiNameList, mWifiWaftList, mWifiIfPassWordList);
        }
        Log.i(TAG, "getWifiInfo: " + "over");
    }

    public void wifiVisibility(){
        whatNet = 2;
        mSelectNetLayout.setVisibility(View.GONE);
        mWifiConnectLayout.setVisibility(View.VISIBLE);
        mEthernetConnectLayout.setVisibility(View.GONE);
        if (NetUtil.isWifiConnect(getActivity())) {
//            toNext2();
            Toast.makeText(getActivity(), getString(R.string.string_wifi_connect_success), Toast.LENGTH_SHORT).show();
        }
        mWifiRefreshButton.setVisibility(View.VISIBLE);
    }

    public void ethernetVisibility(){
        whatNet = 1;
        mSelectNetLayout.setVisibility(View.GONE);
        mWifiConnectLayout.setVisibility(View.GONE);
        mEthernetConnectLayout.setVisibility(View.VISIBLE);
        if (NetUtil.isEthernetConnect(getActivity())) {
//            toNext2();
            Toast.makeText(getActivity(), getString(R.string.string_ethernet_connect_success), Toast.LENGTH_SHORT).show();
        }
        mWifiRefreshButton.setVisibility(View.INVISIBLE);
    }

    /**
     * @param targetView 目标view位置
     */
    public void startNetSelectAnimation(View targetView){
        final ValueAnimator animator = ValueAnimator.ofInt((int)mNetSelectLockCradView.getY(),(int)targetView.getY() + 16);
        animator.setDuration(200);
        animator.setInterpolator(new LinearInterpolator());//线性效果变化
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                Integer integer = (Integer) animator.getAnimatedValue();
                mNetSelectLockCradView.setY(integer);
            }
        });
        animator.start();
    }

    private void showProgressDialog() {
        if (mProgressDialog == null) {
            mProgressDialog = new ProgressDialog(getActivity());
            mProgressDialog.setMessage(getString(R.string.string_google_login_loading));
            mProgressDialog.setIndeterminate(true);
        }

        mProgressDialog.show();
    }

    private void hideProgressDialog() {
        if (mProgressDialog != null && mProgressDialog.isShowing()) {
            mProgressDialog.hide();
        }

    }


    //wifi页逻辑

    class MyWifiSelectOnItemClickListener implements AdapterView.OnItemClickListener{

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            mSelectWifiSSID = mWifiNameList.get(i);
            wifiSSIDText.setText(mSelectWifiSSID);
            startWifiSelectAnimation(view);
            showPassWordLayout();
        }
    }

    class MyWifiSelectOnItemSelectListener implements AdapterView.OnItemSelectedListener{

        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            startWifiSelectAnimation(view);
            hidePassWordLayout();
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    }

    boolean hideBoolean = false;

    public void hidePassWordLayout(){
//        mWifiPassWordEdit.setVisibility(View.GONE);
//        mWifiConnectButton.setVisibility(View.GONE);
        wifiPasswordLayout.setVisibility(View.INVISIBLE);
        hideBoolean = true;
    }

    public void showPassWordLayout(){
//        mWifiPassWordEdit.setVisibility(View.VISIBLE);
//        mWifiConnectButton.setVisibility(View.VISIBLE);
        wifiPasswordLayout.setVisibility(View.VISIBLE);
        mWifiPassWordEdit.requestFocus();
        hideBoolean = false;
    }

    /**
     * @param targetView 目标view位置
     */
    public void startWifiSelectAnimation(View targetView) {
        final ValueAnimator animator = ValueAnimator.ofInt((int) mWifiSelectLockCradView.getY(), (int) targetView.getY() + 105);
//        if (targetView.getY() == 0){
//            return;
//        }
        animator.setDuration(200);
        animator.setInterpolator(new LinearInterpolator());//线性效果变化
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                Integer integer = (Integer) animator.getAnimatedValue();
                mWifiSelectLockCradView.setY(integer);
            }
        });
        animator.start();
    }


    private boolean isEthernetConnect;

    //以太页逻辑
    BroadcastReceiver netWorkChangeReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            //if((whatNet == 2 || whatNet == 1 )&& intent.getAction().toString().equals(CONNECTIVITY_CHANGE_ACTION)){
            if(intent.getAction().equals(CONNECTIVITY_CHANGE_ACTION)){
                    if (NetUtil.isEthernetConnect(context)) {
                        //toNext2();
                        isEthernetConnect = true;
                        Toast.makeText(context, getString(R.string.string_ethernet_connect_success), Toast.LENGTH_SHORT).show();
                        hideProgressDialog();
                        hidePassWordLayout();

                    }else {
                        isEthernetConnect =false;
                    }

                    Log.d("zhaoyf","----intent.getAction()="+intent.getAction());
                    if (NetUtil.isWifiConnect(context)) {
//                        toNext2();
                        Log.d("zhaoyf","wifi connect");
                        Toast.makeText(context, getString(R.string.string_wifi_connect_success), Toast.LENGTH_SHORT).show();
                        hideProgressDialog();
                        hidePassWordLayout();
                    }else {
                        Toast.makeText(context, getString(R.string.string_wifi_connect_failure), Toast.LENGTH_SHORT).show();
                        hideProgressDialog();
                        hidePassWordLayout();
                    }
           // }else if ((whatNet == 2 || whatNet ==1) && intent.getAction().toString().equals(CONNECTIVITY_CHANGE_ACTION_FAILURE) && mProgressDialog.isShowing() && !hideBoolean){
            }else if (intent.getAction().toString().equals(CONNECTIVITY_CHANGE_ACTION_FAILURE) &&null!=mProgressDialog&&mProgressDialog.isShowing() && !hideBoolean){
                Toast.makeText(getActivity(),getString(R.string.string_wifi_connect_failure),Toast.LENGTH_SHORT).show();
                hideProgressDialog();
            }
//            else  if ((whatNet == 2 || whatNet ==1) && intent.getAction().toString().equals(CONNECTIVITY_CHANGE_ACTION_TIMEOUT) ){
//                Toast.makeText(getActivity(),getString(R.string.string_wifi_connect_timeout),Toast.LENGTH_SHORT).show();
//                hideProgressDialog();
//            }

        }
    };


    private void toNext2() {
        Intent intent = new Intent();
        intent.setAction(MainActivity.ACTION_TO_NEXT_PAGER3);
        getActivity().sendBroadcast(intent);
    }




}
